package controllers

import (
	"demochat/jwt"
	"fmt"
	"github.com/beego/beego/v2/core/logs"
	beego "github.com/beego/beego/v2/server/web"
)

type BaseController struct {
	beego.Controller
}

func (c *BaseController) Prepare() {
	token := c.Ctx.Request.Header.Get("Authorization")
	//Id := c.Ctx.Request.Form.Get("user_id")
	//idInt, _ := strconv.Atoi(Id)
	logs.Info(token)
	fmt.Println(len(token))
	var err error
	var id int64
	if len(token) == 120 {
		id, err = jwt.VerificationTk(token)
	} else {
		id, err = jwt.VerificationToken(token)
	}

	if err != nil {
		fmt.Println(err)
		c.Ctx.Redirect(302, "/login") //若Session中无用户ID则302重定向至登陆页面
	}
	fmt.Println(id)
	//fmt.Println(idInt)
	//if id != 4 {
	//	c.Ctx.Redirect(302, "/login")
	//}
}
